<?php
/**
 * PHP Daycare
 * This file allows the user to view and delete the events log
 * @author Jason Butz
 * @version 0.0
 * @package PHPDaycare
 */

include_once("functions.php");
include_once("config.php");
session_start();
// Our user must be logged in to view things, otherwise they get an error
if(loggedInAsAdmin() == 1)
{
	if(isset($_GET['delete']))
	{
		// We are deleting everything in the event log!
		$sql = 'DELETE FROM event';
		$r = $db->query($sql);
		if($r)
		{
			echo "<p>All the event logs were delete.</p>";
		}
		else
		{
			echo "<p>Error. The event logs were not deleted</p>";
		}
	}
	else
	{
		$sql = 'SELECT * FROM event';
		$r = $db->query($sql);
		echo "
		<table cellspacing='1' class='tablesorter' width='100%'>
		<thead>
			<tr>
				<th>Title</th>
				<th>Description</th>
				<th>Time</th>
			</tr>
		</thead>
		<tbody>";
		while($row = mysql_fetch_row($r))
		{
			echo "<tr>
						<td>" . $row[1] . "</td>
						<td>" . $row[2] . "</td>
						<td>" . date("m/d/y h:i A", strtotime($row[3])) . "</td>
				</tr>";
		}
		echo "</tbody></table>";
		$temp->tablePager();
		echo "<script type=\"text/javascript\">loadsorterEvent()</script><p>&nbsp;</p>";
		echo "<p>You can delete all of these records if you wish. This CAN NOT be undone.</p>
			<p><a href=\"#\" onClick=\"loadAdmininfo('event.php', 'delete')\">Delete Event Logs</a></p>";
	}
}
else
{
	$log->loginFailA($_SESSION['user']);
	// They may be logged in, but they are NOT an admin
	// Show an error message on the main page with a menu
	$msg = "Error: You are not an administrator. 
		To access the administrator panel please logout and 
		log back in as a user with administrative privileges.";
	$temp->displayCont($msg, TRUE);
}
?>
